﻿@using Webdiyer.WebControls.Mvc;
@{
    ViewBag.Title = "检查详细 信息列表";
    ViewBag.TextName = "检查详细 信息列表";
    Layout = "~/Views/Shared/Admin.cshtml";
}
<link rel="stylesheet" type="text/css" href="/Res/CSS/css/base.css" />
<link rel="stylesheet" type="text/css" href="/Res/CSS/css/styles.css" />
<link rel="stylesheet" type="text/css" href="/Res/mmGrid/mmGrid.css" />
<link rel="stylesheet" type="text/css" href="/Res/mmGrid/mmPaginator.css" />
<style>
    .mmGrid .mmg-headWrapper .mmg-head th .mmg-titleWrapper {
        height: auto !important;
    }

        .mmGrid .mmg-headWrapper .mmg-head th .mmg-titleWrapper .mmg-title {
            word-break: break-all !important;
            display: block;
            height: 100%;
        }

    .mmGrid .mmg-bodyWrapper .mmg-body tr td {
        padding: 5px;
    }
</style>
<div class="breadcrumb">
    <a href="javascript:void(0);">检查详细 信息列表</a>
</div>
<div class="pd15">
    <div class="calc-box">
        <div class="filter">
            <div class="calc-box">
                <a target="_blank" class="btn btn-danger" href="@Url.Action("DownFile", "PM", new { filePath = "Resource\\人员信息模板.xls", fileName = "人员信息模板.xls" })">下载模板</a>
                <a target="_blank" class="btn btn-danger" href="/UserInfoCheck/ExportExcel">导出数据</a>
                @if (ViewBag.Admin.ToString() == "1")
                {
                    <form id="frmUpload" action="/UserInfoCheck/UFileStu/" method="post" onsubmit="return toVaild()" enctype="multipart/form-data" style="display:inline-block;">
                        上传数据：
                        <input type="file" name="file" id="file" />
                        <input type="submit" class="btn" style="margin-left: 5px; border: 0; width: 70px; height: 26px;" value="导入" />
                    </form>
                }                
            </div>
        </div>
        <div class="operation bd-t pd-t10 pd-b10 mg-t10">
            <div class="fl">
                <a href="/UserInfoCheck/Edit?v=1" class="btn btn-danger"><i class="iconfont">&#xe64d;</i>添加</a>
                <a href="javascript:void(0);" onclick="swapCheck()" class="btn btn-danger">全选</a>
                @if (ViewBag.Admin.ToString() == "1")
                {
                <a href="javascript:void(0);" onclick="Getcheckbox()" class="btn btn-danger"><i class="iconfont">&#xe600;</i>删除</a>
                }
                @*<a href="javascript:void(0);" onclick="searchRepeat()" class="btn" style="margin-left:30px;">查询重复</a>
                <a target="_blank" class="btn btn-normal" href="/UserInfoCheck/ExportRepeatExcel">导出重复数据</a>
                @{
                    if (ViewBag.Admin.ToString() == "1")
                    {
                <a href="javascript:void(0);" onclick="delRepeat()" class="btn btn-warm">删除重复数据</a>
                    }
                }*@
                <div style="margin-left:30px;display:inline-block;">
                    类别：
                    @Html.DropDownList("search_type", (IEnumerable<SelectListItem>)ViewBag.ListSeachType)
                    &nbsp;
                    名称：
                    <input type="text" id="search_input" name="search_input" value="@ViewBag.SeachValue" class="w200" />
                    <input type="hidden" id="txtHandler" name="handler" value="" />
                    <button type="submit" id="btnSearch" class="btn" onclick="search()">查询</button>
                    @{
                        if (ViewBag.Admin.ToString() == "1")
                        {
                            <button type="submit" id="btnDelete" disabled class="btn btn-warm" onclick="search('delete')">查询&删除</button>
                        }
                    }
                </div>
            </div>
        </div>
    </div>
    <div class="grid-100">
        <table id="tblList"></table>
        <div style="text-align:right;">
            <div id="paginator"></div>
        </div>
    </div>
</div>
<div id="outerdiv" style="position:fixed;top:0;left:0;background:rgba(0,0,0,0.7);z-index:9999;width:100%;height:100%;display:none;">
    <div style="width:100%;line-height:50px;background-color:white;font-size:20px;" align="center">查看图片</div>
    <div id="innerdiv" style="position:absolute;">
        <img id="bigimg" style="border:5px solid #fff;" />
    </div>
</div>

<script type="text/javascript" src="/Res/CSS/js/jquery.js"></script>
<script type="text/javascript" src="/Res/CSS/js/jquery-form.js"></script>
<script type="text/javascript" src="/Res/mmGrid/mmGrid.js"></script>
<script type="text/javascript" src="/Res/mmGrid/mmPaginator.js"></script>
<script type="text/javascript">
    var search_type = "";
    var search_input = "";
    var isSearch = false;
    var isSearchDel = false;
    var isRepeat = false;

    var ctlTable = null;
    var pageBar = null;
    var dataItems = [];
    $(function () {
        $('#frmUpload').ajaxForm(function (data) {
            top.hideLoading();
            //if (data.result.status) {
            //    alert("上传数据成功，请刷新数据！");
            //} else {
            //    alert("上传数据失败！");
            //}

            alert(data.result.msg || "刷新页面数据");
        });
        var val = "";
        $("#search_input").keyup(function () {
            if (this.value != val) {
                $("#btnDelete").attr("disabled", true);
                val = this.value;
            }
        });

        top.$("body").append($("#outerdiv"));


        // 表格
        ctlTable = $('#tblList').mmGrid({
            height: "auto",
            nowrap: true,
            //indexCol: true,
            //indexColWidth: 35,
            checkCol: true,
            multiSelect: true,
            cols: [
                { title: '编码', name: 'No', align: 'center' },
                { title: '区县', name: 'Citys', align: 'center' },
                { title: '乡镇', name: 'Towns', align: 'left' },
                { title: '村庄', name: 'Village', align: 'left' },
                { title: '姓名', name: 'Name', align: 'left' },
                { title: '性别', name: 'Sex', width: 60, align: 'center' },
                { title: '身份证号', name: 'UID', width: 130, align: 'center' },
                { title: '民族', name: 'Nation', width: 60, align: 'center' },
                { title: '职业', name: 'ZhiYe', width: 60, align: 'left' },
                { title: '婚姻状况', name: 'HunYing', width: 80, align: 'left' },
                { title: '文化程度', name: 'WenHua', width: 70, align: 'center' },
                { title: '是否户籍人口', name: 'State', width: 80, align: 'center' },
                { title: '未上户原因', name: 'ShangHu', align: 'left' },
                { title: '不纳入筛查原因', name: 'BuNaRu', align: 'left' },
                { title: '近一年外出时间(月)', name: 'YiNian', width: 80, align: 'center' },
                { title: '是否参加2017-2018年体检', name: 'CanJiaTi', width: 80, align: 'center' },
                { title: '本次是否参加现场检测', name: 'CanJiaJian', width: 80, align: 'center' },
                {
                    title: '检测时间', name: 'CanJiaTime', align: 'center', renderer: function (val) {
                        val = val.replace("/Date(", "").replace(")/", "");
                        val = val - 0;
                        if (val < 0) return "";

                        return getTsFormatDate(val);
                    }
                },
                { title: '现场HIV初筛结果', name: 'JieGuo', width: 80, align: 'center' },
                { title: '是否为既往病例', name: 'JiWang', width: 80, align: 'center' },
                { title: '是否采血', name: 'CaiXue', width: 60, align: 'center' },
                { title: 'HIV复检结果', name: 'FuCha', width: 60, align: 'center' },
                { title: 'HIV确证结果', name: 'JieGuoHIV', width: 60, align: 'center' },
                { title: '未检测原因', name: 'WeiJianCe', align: 'left' },
                { title: '备注', name: 'Desc', align: 'left' },
                {
                    title: '照片', name: 'Images', width: 60, align: 'center', renderer: function (val) {
                        return val ? '<a href="javascript:void(0);" onclick="imgShow(\'#outerdiv\', \'#innerdiv\', \'#bigimg\',\'' + escape(val) + '\')">图片</a>' : "否";
                    }
                },
                {
                    title: '操作', name: 'Id', width: 100, align: 'center', lockWidth: true, lockDisplay: true, renderer: function (val) {
                        //return '<a href="/UserInfoCheck/Edit?v=1&id=' + val + '">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" onclick="DelId(' + val + ')">删除</a>';
                        return '<a href="/UserInfoCheck/Edit?v=1&id=' + val + '">编辑</a>';
                    }
                }
            ],
            url: '/UserInfoCheck/CheckList',
            method: 'get',
            root: 'items',
            params: function () {
                return {
                    pageIndex: 1,
                    pageSize: 20,
                    search_input: search_input || "",
                    search_type: search_type || "",
                    isSearchDel: isSearchDel ? 1 : 0,
                    isRepeat: isRepeat ? 1 : 0
                }
            },
            plugins: [
                pageBar = $('#paginator').mmPaginator({
                    //style: 'plain',
                    //totalCountName: 'totalCount',
                    //page: 1,
                    pageParamName: 'pageIndex',
                    limitParamName: 'pageSize',
                    //limitLabel: '每页{0}条',
                    //totalCountLabel: '共<span>{0}</span>条记录',
                    //limit: undefined,
                    limitList: [20, 30, 40, 50]
                })
            ]
        });
        ctlTable.on('loadSuccess', function (e, data) {
            if (isSearchDel) {
                isSearch = false
                $("#btnDelete").attr("disabled", true);
            }
            if (isSearch) {
                $("#btnDelete").removeAttr("disabled");
            }
            dataItems = data["items"] || [];
            pageBar.load({
                totalCount: data["total"],
                pageIndex: data["pageIndex"],
                pageSize: data["pageSize"]
            });
        })
    })

    function toVaild() {
        top.showLoading();
        return true;
    }

    // 查询
    function search(flag) {
        if (flag == "delete") {
            if (!confirm('【谨慎使用】您确定删除查询到的所有数据吗?')) {
                return;
            }
        }
        search_type = $("#search_type").val();
        search_input = $("#search_input").val();
        isSearch = true;
        isSearchDel = flag == "delete";
        isRepeat = false;
        ctlTable.load();
    }

    // 全选
    var isCheckAll = false;
    function swapCheck() {
        if (isCheckAll) {
            $("input[type='checkbox']").each(function () {
                this.checked = false;
            });
            isCheckAll = false;
        } else {
            $("input[type='checkbox']").each(function () {
                this.checked = true;
            });
            isCheckAll = true;
        }
    }
    // 删除
    function Getcheckbox() {
        var selecteds = ctlTable.selectedRowsIndex();

        var chestr = "";
        for (var i = 0, l = selecteds.length; i < l; i++) {

            chestr += (dataItems[i]["Id"] || 0) + ",";
        }
        chestr = chestr.substr(0, chestr.length - 1);
        if (chestr.length <= 0) {
            alert("请选择要删除的选项");
        }
        DelId(chestr);
    }

    // 查询重复
    function searchRepeat() {
        isSearch = false;
        isRepeat = true;
        ctlTable.load();
    }
    // 删除重复
    function delRepeat() {
        isSearch = false;
        if (!confirm('您确定删除重复数据吗?')) {
            return;
        }
        $.ajax({
            type: 'POST',
            url: "/UserInfoCheck/DeleteRepeat",
            data: {},
            dataType: "json",
            success: function (msg) {
                if (msg == "false") {
                    alert("删除重复数据出错或没有重复数据！");
                }
                else {
                    alert("删除成功");
                    //window.location = "/UserInfoCheck/List";
                    ctlTable.load();
                }
            }
        });
    }

    // 删除
    function DelId(ids) {
        isSearch = false;
        if (!confirm('您确定删除吗?')) {
            return;
        }
        $.ajax({
            type: 'POST',
            url: '/UserInfoCheck/Deletes?ids=' + ids,
            data: { ids: ids },
            dataType: "json",
            success: function (msg) {
                if (msg == "false") {
                    alert("删除信息错误，删除失败！");
                }
                else {
                    alert("删除成功");
                    ctlTable.load();
                }
            }
        });
    }

    function addItem() {
        // 获取标识数据
        var dataUrl = "/UserInfoCheck/ReList/",
            flag = true;
        if (dataUrl == undefined || $.trim(dataUrl).length == 0) return false;

        // 选项卡菜单已存在
        top.$('.J_menuTab').each(function () {
            if ($(this).data('id') == dataUrl) {
                if (!$(this).hasClass('active')) {
                    $(this).addClass('active').siblings('.J_menuTab').removeClass('active');
                    scrollToTab(this);
                    // 显示tab对应的内容区
                    top.$('.J_mainContent .J_iframe').each(function () {
                        if ($(this).data('id') == dataUrl) {
                            $(this).show().siblings('.J_iframe').hide();
                            return false;
                        }
                    });
                }
                flag = false;
                return false;
            }
        });

        // 选项卡菜单不存在
        if (flag) {
            var str = '<a href="javascript:;" class="active J_menuTab" data-id="' + dataUrl + '">重复数据<i class="fa fa-times-circle"></i></a>';
            top.$('.J_menuTab').removeClass('active');

            // 添加选项卡对应的iframe
            var str1 = '<iframe class="J_iframe" name="iframe999" width="100%" height="100%" src="' + dataUrl + '" frameborder="0" data-id="' + dataUrl + '" seamless></iframe>';
            top.$('.J_mainContent').find('iframe.J_iframe').hide().parents('.J_mainContent').append(str1);
            top.$('.J_menuTabs .page-tabs-content').append(str);
            scrollToTab(top.$('.J_menuTab.active'));
        }
        return false;
    }

    //1、获取时间戳对应的时间，格式YYYY-MM-DD
    function getTsFormatDate(timeStamp) {
        var date = new Date(timeStamp);
        //console.log(date); 结果为：Tue Apr 02 2019 07:49:23 GMT+0800 (中国标准时间)
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }

    function imgShow(outerdiv, innerdiv, bigimg, src) {
        top.$(bigimg).attr("src", src);//设置#bigimg元素的src属性

        var img = new Image();
        img.onload = function () {
            var windowW = $(top.window).width();//获取当前窗口宽度
            var windowH = $(top.window).height();//获取当前窗口高度
            var realWidth = this.width;//获取图片真实宽度
            var realHeight = this.height;//获取图片真实高度
            var imgWidth, imgHeight;
            var scale = 0.8;//缩放尺寸，当图片真实宽度和高度大于窗口宽度和高度时进行缩放

            if (realHeight > windowH * scale) {//判断图片高度
                imgHeight = windowH * scale;//如大于窗口高度，图片高度进行缩放
                imgWidth = imgHeight / realHeight * realWidth;//等比例缩放宽度
                if (imgWidth > windowW * scale) {//如宽度扔大于窗口宽度
                    imgWidth = windowW * scale;//再对宽度进行缩放
                }
            } else if (realWidth > windowW * scale) {//如图片高度合适，判断图片宽度
                imgWidth = windowW * scale;//如大于窗口宽度，图片宽度进行缩放
                imgHeight = imgWidth / realWidth * realHeight;//等比例缩放高度
            } else {//如果图片真实高度和宽度都符合要求，高宽不变
                imgWidth = realWidth;
                imgHeight = realHeight;
            }
            top.$(bigimg).css("width", imgWidth);//以最终的宽度对图片缩放

            var w = (windowW - imgWidth) / 2;//计算图片与窗口左边距
            var h = (windowH - 50 - imgHeight) / 2;//计算图片与窗口上边距
            top.$(innerdiv).css({ "top": h + 50, "left": w });//设置#innerdiv的top和left属性
            top.$(outerdiv).fadeIn("fast");//淡入显示#outerdiv及.pimg
        }
        img.src = src;

        top.$(outerdiv).click(function () {//再次点击淡出消失弹出层
            $(this).fadeOut("fast");
        });
    }
</script>
